package com.jieshuibao.service.imp;

import java.util.List;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpUserService;
import me.chanjar.weixin.mp.bean.WxMpUserQuery;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList;

import org.springframework.stereotype.Service;

@Service
public class WxAppUserServiceImpl implements WxMpUserService {
	private static final String API_URL_PREFIX = "https://api.weixin.qq.com/sns";
	private WxAppServiceImpl wxAppService;

	public WxAppUserServiceImpl(WxAppServiceImpl wxAppService) {
		this.wxAppService = wxAppService;
	}

	@Override
	public void userUpdateRemark(String openid, String remark)
			throws WxErrorException {
		// TODO Auto-generated method stub

	}

	@Override
	public WxMpUser userInfo(String openid) throws WxErrorException {
		return this.userInfo(openid, null);
	}

	@Override
	public WxMpUser userInfo(String openid, String lang)
			throws WxErrorException {
		String url = API_URL_PREFIX + "/userinfo";
		lang = lang == null ? "zh_CN" : lang;
		String responseContent = this.wxAppService.get(url, "openid=" + openid
				+ "&lang=" + lang);
		System.out.println(responseContent);
		return WxMpUser.fromJson(responseContent);
	}

	@Override
	public List<WxMpUser> userInfoList(List<String> openids)
			throws WxErrorException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<WxMpUser> userInfoList(WxMpUserQuery userQuery)
			throws WxErrorException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public WxMpUserList userList(String nextOpenid) throws WxErrorException {
		// TODO Auto-generated method stub
		return null;
	}

}
